import pandas as pd
import numpy as np


def scale_mean_std(data_df: pd.DataFrame, mean_std_df: pd.DataFrame=None) -> list[pd.DataFrame, pd.DataFrame]:
    """均值-标准差归一化"""
    if mean_std_df is None:
        # data_df_meanstd = data_df.apply(lambda x: (x - np.mean(x)) / np.std(x))
        data_df_meanstd = data_df.copy()
        mean_std_df = pd.DataFrame([])
        for i, one in data_df_meanstd.iteritems():
            mu = np.nanmean(one)
            sigma = np.nanstd(one)
            mean_std_df[i] = pd.Series([mu, sigma], index=['mu', 'sigma'])
            data_df_meanstd[i] = (one - mu)/sigma

        return [data_df_meanstd, mean_std_df]
    else:
        data_df_meanstd = data_df.copy()
        for i, one in data_df_meanstd.iteritems():
            mu = mean_std_df.loc['mu', i]
            sigma = mean_std_df.loc['sigma', i]
            data_df_meanstd[i] = (one - mu)/sigma
        return [data_df_meanstd, mean_std_df]

